package VN.EDU.IMIC.DEVELOPER.TRANTHITHANHNGA.ARRAY.EX4;

public class Models {

	public int min(int[] arr) {
		int min = arr[0];
		for (int i = 0; i < arr.length; i++) {
			if (min > arr[i]) {
				min = arr[i];
			}
		}
		return min;
	}

	public int max(int[] arr) {
		int max = arr[0];
		for (int i = 0; i < arr.length; i++) {
			if (max < arr[i]) {
				max = arr[i];
			}
		}
		return max;
	}

	/**
	 * Finding array contains minimum values/ maximum values
	 * 
	 * @param int[]arr, shOpt =0 min, shOpt= 1 max
	 * @return int[]minOrMaxArrShort
	 */
	public int[] minOrMaxArray(int[] arr, int number) {

		int[] minOrMaxArr = new int[arr.length];
		int iCount = 0;
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] == number) {
				minOrMaxArr[iCount] = i;
				iCount++;
			}
		}

		int[] minOrMaxArrShort = new int[iCount];
		System.arraycopy(minOrMaxArr, 0, minOrMaxArrShort, 0, iCount);
		return minOrMaxArrShort;

	}
}
